package com.cuhk.gulimall.search.vo;

import com.cuhk.common.to.es.SkuEsModel;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class SearchResult {
    // 查询到的所有商品信息
    private List<SkuEsModel> products;
    // 当前页码
    private Integer pageNum = 1;
    // 总记录数
    private Long total;
    // 总页数
    private Integer totalPages;

    // 可以遍历到的全部页码
    // 用于前端模板的渲染显示
    private List<Integer> pageViews;

    // 查询结果中所有涉及到的品牌
    private List<BrandVo> brands;
    // 查询结果中涉及到的所有属性
    private List<AttrVo> attrs;
    // 查询结果中涉及到的所有分类
    private List<CatelogVo> catelogs;

    // 面包屑导航数据
    private List<NavVo> navs;

    @Data
    public static class NavVo {
        private String navName;
        private String navValue;
        private String linkAfterCancel;
    }

    @Data
    public static class BrandVo {
        private Long brandId;
        private String brandName;
        private String brandImg;
    }

    @Data
    public static class AttrVo {
        private Long attrId;
        private String attrName;
        // 该属性所能涉及到的所有值
        private List<String> attrValue;
    }

    @Data
    public static class CatelogVo {
        private Long catelogId;
        private String catelogName;
    }

    public void addProducts(SkuEsModel skuEsModel) {
        if(products == null){
            products = new ArrayList<>();
        }
        products.add(skuEsModel);
    }

    public void addCatelogs(CatelogVo catelogVo) {
        if(catelogs == null){
            catelogs = new ArrayList<>();
        }
        catelogs.add(catelogVo);
    }

    public void addBrand(BrandVo brandVo) {
        if(brands == null) {
            brands = new ArrayList<>();
        }
        brands.add(brandVo);
    }

    public void addAttr(AttrVo attrVo) {
        if(attrs == null) {
            attrs = new ArrayList<>();
        }
        attrs.add(attrVo);
    }

    public void fillPageViews() {
        if(pageViews == null){
            pageViews = new ArrayList<>();
        }
        for(int i = 1; i <= totalPages; i++) {
            pageViews.add(i);
        }
    }


}
